package com.rongshu.view.userInfo.presenter;

import android.content.Context;

import com.rongshu.api.FileUploadService;
import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetBean;
import com.rongshu.view.home.entity.UserInfo;
import com.rongshu.view.login.entity.UpLoadFile;
import com.rongshu.view.userInfo.entity.UpLoadImage;
import com.rongshu.view.userInfo.iview.PerfectInfomationView;

import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.http.PartMap;
import rx.Subscriber;

public class PerfectInfomationPresenter extends BasePresenter<PerfectInfomationView> {

    public PerfectInfomationPresenter(Context context) {
        super(context);
    }

    /**
     * 图片上传
     */
    public void postUploadMoreFile(@PartMap Map<String, RequestBody> files) {
        FileUploadService.uploadMoreFile(files)
                .subscribe(new Subscriber<UpLoadImage>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        if (getView() != null) {
                            getView().uploadImageResult(null,false);
                        }
                    }

                    @Override
                    public void onNext(UpLoadImage upLoadImage) {
                        if (getView() != null) {
                            getView().uploadImageResult(upLoadImage,true);
                        }
                    }
                });
    }

    /**
     * 完善用户基本信息
     */
    public void postUserSetPerfectInfo(int user_id, String pseudonym, String sex,
                                       String birthday, String city, String sign, UpLoadFile upLoadFile) {
        RetorfitService.postUserSetPerfectInfo(user_id, pseudonym, sex, birthday, city, sign, upLoadFile)
                .subscribe(new Subscriber<INetBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(INetBean iNetBean) {
                        if (getView() != null) {
                            getView().onPerfectInfo(iNetBean);
                        }
                    }
                });
    }

    /**
     * 获取用户资料
     */
    public void getUserInfo(int user_id, String sign) {
        RetorfitService.getUserInfo(user_id, sign)
                .subscribe(new Subscriber<UserInfo>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(UserInfo userInfo) {
                        if (getView() != null) {
                            getView().onUserInfo(userInfo);
                        }
                    }
                });
    }
}
